package com.zto.mybatis.custom;

import sun.misc.ProxyGenerator;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by xingyuchao on 2017-07-04.
 *
 */
public class Main {

    public static void main(String[] args) throws IOException {
        //TODO
        MySqlSession mySqlSession = new MySqlSession();
        User2 user = (User2) mySqlSession.selectOne(User2MapperXml.methodSqlMapping.get("selectByPrimaryKey"), 1);

        /*代理模式：执行者和被代理者  被代理者：User2Mapper   执行者：MapperProxy(代理处理器)*/
        User2Mapper mapper = mySqlSession.getMapper(User2Mapper.class);
        User2 user2 = mapper.selectByPrimaryKey(1);
        System.out.println(user2);




        //获取字节码内容
        byte[] data = ProxyGenerator.generateProxyClass("$Proxy0",new Class[]{User2Mapper.class});

        FileOutputStream fos = new FileOutputStream("E:\\idea workspace\\zto-mybatis-practical\\$Proxy0.class");
        fos.write(data);
        fos.close();
    }

}
